package dao.search;

import bean.search.ArrearsSearch;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import util.C3p0Util;

import java.sql.SQLException;
import java.util.List;


/**
 * 欠费查询数据交互实现类
 * */
public class ArrearsSearchDao {
    public List<ArrearsSearch> findAll(){
        List<ArrearsSearch> arrearsSearchList = null;
        /*
            1.创建sql的执行器
                在不使用事务的情况下，需要指定一个数据源
                QueryRunner 对象处理连接以及关闭连接
         */
        QueryRunner runner = new QueryRunner(C3p0Util.getDs());
        String sql = "select * from t_giveMoney";

        try {
            /*
                会将数据封装到对应的对象集合中
             */
            arrearsSearchList = runner.query(sql,new BeanListHandler<>(ArrearsSearch.class));

        } catch (SQLException e) {
            e.printStackTrace();
        }
        return arrearsSearchList;
    }

    public static void main(String[] args) {
        ArrearsSearchDao se  = new ArrearsSearchDao();
        List<ArrearsSearch> inChecks = se.findAll();
        System.out.println(inChecks.toString());

    }
}
